<?php
class Helpers_Validation {
	public $mess;
	public $check;
	
	public function check_empty($data,$error)
	{
		if($data=="")
		{
			$this->mess[]=$error;
		}
		
	}
	public function check_email($email,$error)
	{
		$pattern="/^[a-zA-Z]{1,}[a-zA-Z0-9\_\-\.]+\@[a-zA-Z0-9]{3,}(\.[a-zA-Z]{2,})+$/";
		if(!preg_match($pattern,$email)){
			 $this->mess[]=$error;
		}
	}
	
	public function check_username($username,$error)
	{	
		//======6->20 letter, only alphanumeric and space
		$pattern="/^[a-zA-Z0-9\@\.\s\-]{2,35}$/";
		if(!preg_match($pattern,$username))
		{
			$this->mess[]=$error;
		}
		
	}
	public function check_username_comment($username,$error)
	{	//======6->20 letter, only alphanumeric and space
		$pattern="/^[a-zA-Z0-9\s-]{2,20}$/";
		if(!preg_match($pattern,$username))
		{
			$this->mess[]=$error;
		}
		
	}
	
	public function check_url($url,$error)
	{
		$pattern="/^http(s)?:\/\/[a-z0-9-]+(\.[a-z0-9-]{2,})+$/i";
		if(!preg_match($pattern,$url))
		{
			$this->mess[]=$error;
		}
		
	}
	public function check_match($str1,$str2,$error)
	{
		
		if($str1!=$str2)
		{
			$this->mess[]=$error;
		}
		
	}
	public function check_image_upload($str,$error)
	{	//only jpg of jpeg to create thumnail=============
		 $ext = strtolower(end(explode('.',$str)));
		 if ($ext == 'jpg'||$ext == 'jpeg' || $ext='png'){
		 }
		 else{
		   $this->mess[]=$error;
		 }
	
	}
	public function check_image_size($size,$error)
	{	//only jpg of jpeg to create thumnail=============
			if ($size > 500*1024)
			{ //500KB MAX ==========
			 $this->mess[]=$error;
			}
	
	}
   
	public function valid()
	{
		if($this->mess != "")
		{
			$this->check=false;
		}
		else
		{
			$this->check=true;
		}
		return $this->check;
	}
}
?>